'GCV_FRONT = 2
'GCV_LEFT = 4
'GCV_RIGHT = 5
'GCV_EXTENDED = 7
'GCV_SIMPLIFIED = 8
'GCV_STANDARD = 9
'SIDE = GCV_FRONT

'DETAIL_LEVEL = GCV_STANDARD 'GCV_EXTENDED

hatchAngle  = 45                  
'hatchStep= 2                   

drawFace1 =1

'PAR_din=20
'PAR_d=47
'PAR_b=14
'PAR1_dain= (25+26) * 0.5
'PAR1_da= 42
'PAR1_dw=7.94
'PAR1_r = 1.5
'PAR2_r1 = 1.5

'PAR2_oneShayba =1 ' 1 - ODHA shayba Or 2

Dim math,iDA,iPoint
Const POINT_ARR = 2  
Const ko_MathPointParam = 14

''PAR_AXIS = 1
''PAR_Simpl_AXIS = 1 
'++++
SUB LINE (x1,y1,x2,y2,t) Doc.ksLineSEG x1,y1,x2,y2,t END SUB
SUB Circle (x1,y1,r,t) Doc.ksCircle x1,y1,r,t END SUB
'++++
SUB DrawBall (xtr, ytr, rads, del)
  Line  xtr-rads-del,ytr,xtr+rads+del,ytr,3
  Line  xtr,ytr+rads+del,xtr,ytr-rads-del,3
  Circle xtr,ytr,rads,1
end sub
'++++
sub DrawShayba ( x,  rn,  rv, h, kx, ky ) 
  line  x, rv*ky, x, rn*ky, 1
  line  x, rn*ky, x+h*kx,  rn*ky, 1
  line  x+h*kx,  rn*ky,x+h*kx,  rv*ky, 1

Doc.kshatch  0, hatchAngle, h*0.5,0 , 0, 0
     line x, rv*ky, x, rn*ky, 1
     line x, rn*ky, x+h*kx,  rn*ky, 1
     line x+h*kx,  rn*ky,x+h*kx,  rv*ky, 1
     line x+h*kx,  rv*ky, x, rv*ky, 1
Doc.ksEndObj 
end sub

'++++
SUB Contur (rn, rf1, rf2,rf3, rf4, b,  ky) 
 x1=rf1
 x2=rf2
 x3=b-rf3
 x4=b-rf4
 y2=(rn-rf2)*ky
 y3=(rn-rf3)*ky
  doc.ksArcByPoint x2,y2,rf2,0,y2,x2,rn*ky,-ky,1 ';  /*5*/
  line x2,rn*ky,x3,rn*ky,1
 doc.ksArcByPoint x3,y3,rf3,x3,rn*ky,b,y3,-ky,1 ' ; /*6*/
 Line 0, y2, 0,0,1
 Line b,y3,b,0,1
END SUB
'++++
SUB Apx (rn)
  doc.ksColouring &HFE000000
Contur rn, PAR2_r1, PAR1_r, PAR1_r,  PAR2_r1, PAR_B, 1
Contur rn, PAR2_r1, PAR1_r, PAR1_r,  PAR2_r1, PAR_B, -1
doc.ksEndObj
END SUB
'++++
SUB Script_OnLoad ()

Set math = Kompas.GetMathematic2D
Set iDA = Kompas.GetDynamicArray(POINT_ARR)
Set iPoint = Kompas.GetParamStruct(ko_MathPointParam)

   ys=( PAR_din+PAR_D)*0.25    
   xs=PAR_B*0.5                   
   rn=PAR_D*0.5  
   rv=PAR_din*0.5  
   rv2=PAR1_dain*0.5  
   rn2=PAR1_Da*0.5  
   rsh = PAR1_Dw*0.5    
  if rv2 < (ys-0.8*rsh) then
    rv2 = ys-0.8*rsh
end if  
  if rn2 > (ys+0.8*rsh) then
    rn2 = ys+0.8*rsh  
end if
   xL = (PAR_B - PAR1_Dw)*0.25*1.3  
if PAR2_oneShayba=1 then
xR = 0
else
xR = PAR_B - xL
end if 

   h = 1.2*xL/3  
  if  h > 1.5 then
    h = 1.5  
end if
   rv1 = ( rv + rv2 ) *0.5  
   rn1 = ( rn + rn2 ) *0.5  

APX rn

SELECT CASE DETAIL_LEVEL
      Case GCV_EXTENDED:

        DrawOutsideRing  rn, rn2, PAR_B, PAR1_r, xs, ys, rsh, xL, xR, rn1, h, 1   
        DrawBall  xs, ys, rsh, 2  
        DrawInsideRing  rv, rv2, PAR_B, PAR2_r1, xs, ys, rsh,xL, xR, rv1, 1   
        DrawShayba   xL,  rn1,  rv1, h, -1, 1   
        if PAR2_oneShayba <>1 then
          DrawShayba  xR,  rn1,  rv1, h, 1, 1   
        End If
        
         If PAR_AXIS <> 1 Then 
          line  0, rn-PAR1_r, 0, rv+PAR2_r1, 1   
          line  PAR_B, rn-PAR1_r, PAR_B, rv+PAR2_r1, 1   
         End If    

        DrawOutsideRing  rn, rn2, PAR_B, PAR1_r, xs, ys, rsh,xL, xR, rn1, h, -1   

        DrawBall xs, -ys, rsh, 2  
        DrawInsideRing   rv, rv2, PAR_B, PAR2_r1, xs, ys, rsh,xL, xR, rv1, -1   
        DrawShayba  xL,  rn1,  rv1, h, -1, -1   

        if PAR2_oneShayba <>1 then
          DrawShayba   xR,  rn1,  rv1, h, 1, -1 
        End if  
      If PAR_AXIS <> 1 Then  
          line  0,-( rn-PAR1_r), 0, -(rv+PAR2_r1), 1   
          line  PAR_B, -(rn-PAR1_r), PAR_B, -(rv+PAR2_r1), 1   
      End If 


  case  GCV_STANDARD:
          DrawOutsideRing  rn, rn2, PAR_B, PAR1_r, xs, ys, rsh,xL, xR, rn1, h, 1   

          DrawBall  xs, ys, rsh, 2  
          DrawInsideRing rv, rv2, PAR_B, PAR2_r1, xs, ys, rsh,xL, xR, rv1, 1   

          DrawShayba  xL,  rn1,  rv1, h, -1, 1   
         
 if  PAR2_oneShayba <>1 then
            DrawShayba   xR,  rn1,  rv1, h, 1, 1   
         End if
  If PAR_AXIS <> 1 Then     
       line  0, rn-PAR1_r, 0, rv+PAR2_r1, 1   
       line  PAR_B, rn-PAR1_r, PAR_B, rv+PAR2_r1, 1   
  End If         

          DrawSimple rv, rn, PAR2_r1, PAR1_r, PAR1_r,  PAR2_r1, PAR_B, -1

          CASE GCV_SIMPLIFIED:
        DrawSimple rv, rn, PAR2_r1, PAR1_r, PAR1_r,  PAR2_r1, PAR_B, 1  
        DrawSimple rv, rn, PAR2_r1, PAR1_r, PAR1_r,  PAR2_r1, PAR_B, -1  

END SELECT

 iDA.ksDeleteArray

END SUB  
'+++++
 Sub DrawInsideRing( rv, rv2, b, r, xs,ys, rads,xL,  xR,  rSh,  ky )
y2=(rv+r)*ky  
I=0
Dim  xp(2),yp(2)
iDA.ksClearArray
  math.ksIntersectLinsCir 0,rv2*ky,b,rv2*ky,xs,ys*ky,rads,iDA
I = iDA.ksGetArrayCount

  if  i <>0  then
iDA.ksGetArrayItem 0, iPoint
    xp(0) = iPoint.x

            if i = 1 then
                xp(1) = xp(0)  
           else 
             iDA.ksGetArrayItem 1, iPoint
             xp(1) = iPoint.x
           if  xp(1)< xp(0) then
         x = xp(0)  
        xp(0) = xp(1)  
        xp(1) = x  
 end if     
            end if

    if  xL > 0.001 then
      line 0,rSh*ky,xL,rSh*ky,1  
      line  xL,rv2*ky,xp(0),rv2*ky,1  
    else
      line 0,rv2*ky,xp(0),rv2*ky,1  
  end if

    if  xR > 0.001 then
      line  xp(1), rv2*ky, xR, rv2*ky, 1  
      line  xR, rSh*ky, b, rSh*ky, 1  
   else
      line xp(1),rv2*ky,b,rv2*ky,1
 end if  

 else
    line 0,rv2*ky,b,rv2*ky,1  
 end if

 doc.ksArcByPoint b-r,y2,r,b,y2,b-r,rv*ky,-ky,1  
  line b-r,rv*ky,r,rv*ky,1  
 doc.ksArcByPoint r,y2,r,r,rv*ky,0,y2,-ky,1  
  
  If PAR_AXIS = 1 Then
    line r,rv*ky,r,0,1  
    line b-r,rv*ky,b-r,0,1  
  End If 
  
Doc.kshatch  0, hatchAngle-90, hatchStep, 0, 0, 0 
      yy = rv2*ky  
    if  i <>0 then

       if  xL > 0.001 then
         line 0,rSh*ky,xL,rSh*ky,1  
         line xL,rSh*ky,xL,rv2*ky,1  
         line  xL,rv2*ky,xp(0),rv2*ky,1  
       else
         line 0,rv2*ky,xp(0),rv2*ky,1  
      end if

      if i > 1 then
        doc.ksArcByPoint xs,ys*ky,rads,xp(0),rv2*ky,xp(1),rv2*ky,ky,1  
       end if

       if  xR > 0.001 then
         line xp(1), rv2*ky, xR, rv2*ky, 1  
         line xR, rv2*ky, xR, rSh*ky, 1  
         line xR, rSh*ky, b, rSh*ky, 1  
         yy = rSh*ky  
       else
         line xp(1),rv2*ky,b,rv2*ky,1  
    end if

    else
    line 0,rv2*ky,b,rv2*ky,1  
end if
    line b,yy,b,y2,1  
    doc.ksArcByPoint b-r,y2,r,b,y2,b-r,rv*ky,-ky,1  
    line b-r,rv*ky,r,rv*ky,1  
    doc.ksArcByPoint r,y2,r,r,rv*ky,0,y2,-ky,1  
    line 0,y2,0,rSh*ky,1  
        Doc.ksEndObj 
end sub

'+++++
Sub DrawOutsideRing ( rn,   rn2,  b,  r,  xs,ys,  rads, xL,  xR,  rSh,  h, ky)
 I=0  
 y3=(rn-r)*ky  
DIM  xp(2), yp(2)

iDA.ksClearArray
  math.ksIntersectLinsCir 0,rn2*ky,b,rn2*ky,xs,ys*ky,rads,iDA
  I = iDA.ksGetArrayCount  
  doc.ksArcByPoint r,y3,r,0,y3,r,rn*ky,-ky,1  
  line r,rn*ky,b-r,rn*ky,1  
  doc.ksArcByPoint b-r,y3,r,b-r,rn*ky,b,y3,-ky,1  
  if  i <>0 then
iDA.ksGetArrayItem 0, iPoint
   xp(0) = iPoint.x
    if i =1 then
      xp(1) = xp(0)  

    else 
iDA.ksGetArrayItem 1, iPoint
      xp(1) = iPoint.x

      if  xp(1)< xp(0) then
         x = xp(0)  
        xp(0) = xp(1)  
        xp(1) = x  
      end if
    end if
    if  xR > 0.001 then
      line  b, rn2*ky, xR+h, rn2*ky, 1   
      line xR, rn2*ky,xp(1),rn2*ky, 1   
  
    else
      line b,rn2*ky,xp(1),rn2*ky,1
end if  
    if  xL> 0.001 then
      line xp(0),rn2*ky,xL,rn2*ky,1  
      line xL-h,rn2*ky,0,rn2*ky,1 
    else
      line xp(0),rn2*ky,0,rn2*ky,1 
 end if
  else 
    Line b,rn2*ky, 0,rn2*ky,1   
  end if
Doc.kshatch  0, hatchAngle, hatchStep, 0, 0, 0   
 Line 0,rn2*ky,0,y3,1  
doc.ksArcByPoint r,y3,r,0,y3,r,rn*ky,-ky,1  
    line r,rn*ky,b-r,rn*ky,1  
    doc.ksArcByPoint b-r,y3,r,b-r,rn*ky,b,y3,-ky,1  
    line b,y3,b,rn2*ky,1  

    if  i <>0 then
      if xR > 0.001 then
        line  b, rn2*ky, xR+h, rn2*ky, 1   
        line  xR+h, rn2*ky, xR+h, rSh*ky, 1   
        line xR+h, rSh*ky,xR, rSh*ky, 1   
        line xR, rSh*ky,xR, rn2*ky, 1   
        line  xR, rn2*ky,xp(1),rn2*ky, 1   
      else
        line b,rn2*ky,xp(1),rn2*ky,1  
      end if

      if  i>1 then
        doc.ksArcByPoint xs,ys*ky,rads,xp(1),rn2*ky,xp(0),rn2*ky,ky,1  
end if
      if xL> 0.001 then
        line xp(0),rn2*ky,xL,rn2*ky,1  
        line xL,rn2*ky,xL,rSh*ky,1  
        line xL,rSh*ky,xL-h,rSh*ky,1  
        line xL-h,rSh*ky,xL-h,rn2*ky,1  
        line xL-h,rn2*ky,0,rn2*ky,1  
      else
        line xp(0),rn2*ky,0,rn2*ky,1
end if  
       else
      line b,rn2*ky, 0,rn2*ky,1 
end if  

    Doc.ksEndObj

If PAR_AXIS = 1 Then
   Line b,y3,b,0,1  
   Line 0,y3,0,0,1  
   if  ky = 1 then
     line -2, 0, b+2, 0, 3   
   end if 
End If 
 
end sub
'++++++++
sub DrawSimple (rv, rn, rf1, rf2,rf3, rf4, b,  ky) 


 x1=rf1
 x2=rf2
 x3=b-rf3
 x4=b-rf4

 y1=(rv+rf1)*ky
 y2=(rn-rf2)*ky
 y3=(rn-rf3)*ky
 y4=(rv+rf4)*ky

  if  drawFace1=1 then
    line 0,y1,0,y2,1
end if

  doc.ksArcByPoint x2,y2,rf2,0,y2,x2,rn*ky,-ky,1 ';  /*5*/
  line x2,rn*ky,x3,rn*ky,1
  doc.ksArcByPoint x3,y3,rf3,x3,rn*ky,b,y3,-ky,1 ' ; /*6*/
  line b,y3,b,y4,1
doc.ksArcByPoint x4,y4,rf4,b,y4,x4,rv*ky,-ky,1 '; /*7*/
  line x4,rv*ky,x1,rv*ky,1
  doc.ksArcByPoint x1,y1,rf1,x1,rv*ky,0,y1,-ky,1 ';     /*8*/

 If PAR_Simpl_AXIS = 1 Then 
  line x1,y1,x3,y3,2
  line x2,y2,x4,y4,2
  Else 
 ''NEW 
   Line b/3,(rn+rv)*0.5*ky,2*b/3,(rn+rv)*0.5*ky,2
   Line b*0.5,((rn+rv)*0.5-b/6)*ky,b*0.5,((rn+rv)*0.5+b/6)*ky,2
   ''
 End If   
  if PAR_AXIS = 1 THEN  
    line b,0,b,y4,1
    line x1,0,x1,rv*ky,1
    line x4,0,x4,rv*ky,1
    if  drawFace1 =1 then
      line 0,y1,0,0,1
   end if
     if ky = 1  then
      line -2, 0, b+2, 0, 3
end if
  end if
end sub
'+++++++++++++++
'+++++
